﻿/****************************************************
	文件：MsgHandler.cs
	作者：HuskyT
	邮箱:  1005240602@qq.com
	日期：2020/04/26 19:39   	
	功能：接收消息后，具体的处理逻辑（方法名必须和协议名一致（接收消息时使用反射调用）；参数为固定的：Client、MsgBase）
*****************************************************/

using HTServer.Business;
using HTServer.Proto;

namespace HTServer.Net
{
    public class MsgHandler
    {
        public static void MsgSecret(Client client, MsgBase msg)
        {
            MsgSecret m = (MsgSecret)msg;
            m.SecretKey = Server.SecretKey;
            Server.Send(client, m);
        }
        public static void MsgPing(Client client, MsgBase msg)
        {
            client.LastPingTime = Server.GetTimeStamp();
            MsgPing m = new MsgPing();
            Server.Send(client, m);
        }
        public static void MsgRegister(Client client, MsgBase msg)
        {
            MsgRegister m = (MsgRegister)msg;
            RegisterResult result = UserMgr.Instance.Register(m.RegisterType, m.Username, m.Password, out string token);
            m.Result = result;
            m.NewToken = token;
            Server.Send(client, m);
        }
        public static void MsgLogin(Client client, MsgBase msg)
        {
            MsgLogin m = (MsgLogin)msg;
            LoginResult result = UserMgr.Instance.Login(m.LoginType, m.Username, m.Password, out int userId, out string token);
            m.Result = result;
            m.NewToken = token;
            client.UserId = userId;
            Server.Send(client, m);
        }


        #region Test
        public static void MsgTestSubcontract(Client client, MsgBase msg)
        {
            MsgTestSubcontract m = (MsgTestSubcontract)msg;
            //一次性发送大量数据，底层进行分包优化：
            m.RecContent = "分包测试，来自服务器的信息：huskyTGame.github.io+hyiutoyhngjluopugaehyiutoyhnghyiutoyhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhsfasfadsadagfagdagfagaehyiutoagfagaehyiutoyhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhssfagfagayhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhssfagfadagfagaehyiutoagfagaehyiutoyhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhssfagfagayhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhssfagfagaehyiutoyhngjluopdvquosdbnmzxnggfagaehyiutoyhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhsdhwqwnjfkrhvcbxcnfzvhsgfagaehyiugfagfagaehyiutoyhngjluopujjggsdvqugaehyiutoyhngjluopdvquosdbnmzxnggfagaehyiutoyhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhsdhwqwnjfkrhvcbxcnfzvhsgfagaehyiugfagfagaehyiutoyhngjluopujjggsdvquaehyiutoagfagaehyiutoyhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhssfagfagayhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhssfagfagaehyiutoyhngjluopdvquosdbnmzxnggfagaehyiutoyhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhsdhwqwnjfkrhvcbxcnfzvhsgfagaehyiugfagfagaehyiutoyhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhsgaehyiutoyhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhstoyhngjluopujjggsdvquosdbnmzxngdhwqwnjfkrhvcbxcnfzvhs";
            Debug.Log(m.ReqContent);
            Server.Send(client, m);
        }
        public static void MsgTestStick(Client client, MsgBase msg)
        {
            MsgTestStick m = (MsgTestStick)msg;
            m.RecContent = "粘包测试，来自服务器的信息";
            Debug.Log(m.ReqContent);
            //发送多次小数据，底层进行粘包优化：
            Server.Send(client, m);
            Server.Send(client, m);
            Server.Send(client, m);
            Server.Send(client, m);
            Server.Send(client, m);
            Server.Send(client, m);
        }
        #endregion
    }
}